# -*- coding: utf-8 -*-
from django.core.management.base import BaseCommand
from projects.models import Poll, Vote, Project
from django.contrib.auth.models import User
from profiles.models import Profile

class Command(BaseCommand):
    def handle(self, *args, **options):
        print "generating votes..."
        for obj in Vote.objects.all():
            obj.delete() 
        for obj in Poll.objects.all():
            obj.delete()
        for obj in User.objects.filter(username__contains="testuser"):
            obj.delete()
        users = [User(username="testuser%i"%i) for i in xrange(20)]
        map(lambda u: u.save(), users)
        polls = [Poll(month=2, year=2004),
                 Poll(month=2, year=2003),
                 Poll(month=3, year=2004)]
        for poll in polls:
            poll.save()
            for user in users:
                p = Project.objects.order_by("?")[0]
                poll.vote(user, p)
        print "done."